const keepAliveStore = defineStore(
  'keepAlive',
  {
    state: () => ({
      currentKeepAliveList: [],
      keepAliveList: [],
    }),
    actions: {
      pushKeepaliveList(data){
        if (data && !this.keepAliveList.some((item) => item === data)) {
          this.keepAliveList.push(data)
          this.currentKeepAliveList.push(data)
        }
      },
      closeKeepaliveList(data){
        this.currentKeepAliveList = this.keepAliveList.filter(item => item !== data.name)
        const timer = setTimeout(() => {
          this.keepAliveList = this.keepAliveList.filter(item => item !== data.name)
          clearTimeout(timer)
        }, 200);
        
      },
      clearKeepaliveList() {
        return new Promise(async (resolve, reject) => {
          this.currentKeepAliveList = []
          const timer = setTimeout(() => {
            this.keepAliveList = []
            clearTimeout(timer)
            resolve()
          }, 1000)
        })
      },
    }
  })

export default keepAliveStore
